import { BrowserWindow } from 'electron'
import { is } from '@electron-toolkit/utils'
import { windowConfig } from '../config/window'
import { join } from 'path'

let chatWindow = null

export function createChatWindow() {
  chatWindow = new BrowserWindow(windowConfig.chat)

  if (is.dev) {
    chatWindow.webContents.openDevTools()
  }

  chatWindow.on('ready-to-show', () => {
    chatWindow.show()
  })

  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    chatWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/#/chat`)
  } else {
    chatWindow.loadFile(join(__dirname, '../../renderer/index.html'), {
      hash: '/chat'
    })
  }

  return chatWindow
} 